import { Component, OnInit, ViewChild, AfterViewInit, OnDestroy } from '@angular/core';
import { HttpService } from 'src/app/service/http.service';
import { ToolService } from 'src/app/service/tool.service';
import { IonSlides, NavController, Platform, AlertController } from '@ionic/angular';
import { UrlService } from 'src/app/service/url.service';
import { ConfigService } from 'src/app/service/config.service';
import { Router } from '@angular/router';
import * as $ from 'jquery';
import { PopwinService } from 'src/app/service/popwin.service';
import { Storage } from '@ionic/storage';
import { EventService } from 'src/app/service/event.service';
import { InAppBrowser } from '@ionic-native/in-app-browser/ngx';

@Component({
  selector: 'app-index3rd',
  templateUrl: './index3rd.page.html',
  styleUrls: ['./index3rd.page.scss'],
})
export class Index3rdPage implements OnInit,AfterViewInit,OnDestroy {

  
  imgArr = [];
  url = ConfigService.SERVER_PATH;
  @ViewChild('slides') slides;
  slideOpts = {
    effect: 'flip',  //轮播效果
    autoplay: {
      delay: 2000,
    },
    loop:true
  };
  firstFlag = false; secodFlag = true; thirdFlag = false;
  markIndex = -1;
  lots = [];
  lots1 = [];
  lots2 = [];
  lotsImg=""; //万漉彩票的banner图片
  nowTime;
  objectKeys = Object.keys;
  noticeArr = [];
  private allTimerArr = []; private hotTimerArr = []; private collectTimerArr = [];
  private tempRefreshTimeNetArr:any[]=[];
  public isNoDevice:boolean=false;
  private isOpen:boolean=true;

  //第三方入口相关
  public thirdStatus=0;
  public entertainment=[];//真人游戏的数据列表
  public electronicGame=[];//游戏的列表数据(电子游戏)
  public isEleGame=true; //是否选中电子游戏
  public electronicGameSp=[];
  public electronicGameTwo=[];//游戏列表的数据(街机)
  public isEleGameTwo=false;//是否选中街机
  public sportList=[]; //AG的真人游戏的数据
  public isAGSport=false;  //是否选中AG体育的数据
  public isChessGame=true; //是否选中开元棋牌
  public isChessGameTwo=false;//是否选中双赢棋牌

  public sprotBookList=[];//利己SBO的数据
  public isSBOSport=false;//是否选中SBO体育的数据

  public sgList=[]; //双赢彩票的列表数据
  public sgBanner=""; //双赢彩票的banner

  public psList=[];  //平博体育的数据
  public isPSSport=true; //是否选中平博体育


  public balance=0;//平台的总可用余额
  public listInfo=[];//其他平台(AG)的可用余额
  public inputVal="";//输入可转的树
  public ng_game_code="";//第三方的游戏标识

  public KYData=[];//开元游戏列表的数据
  private kindId=0;
  public SWData=[];//双赢棋牌游戏列表的数据
  private gameId=0;

  private inAppBrowserOption="location=no,enableViewportScale=yes";
  public serverPath=ConfigService.SERVER_PATH;


  constructor(private http: HttpService, private navCtrl: NavController, private router: Router, private popWin: PopwinService, private eventS: EventService, private store: Storage,private platform :Platform,private iab:InAppBrowser,private alertController:AlertController) { }

  ngOnInit() {
    if(!ConfigService.is3rd){
        this.navCtrl.navigateRoot("/tabs/home");
        return;
    }
    this.menuNet();
    this.test();
    this.noticeData();
    this.sliderData();
    this.initEvent();
    if(!this.platform.is("cordova")){
        this.isNoDevice=true;
    }else{
        this.isNoDevice=false;
    }

    this.getBlanceMoney(); //初始化获取余额
  }

  doRefresh(event) {
    this.menuNet();
    this.timeNet();
    this.noticeData();
    setTimeout(() => {
      event.target.complete();
    }, 2000);
  }

  initEvent() {
    let that = this;
    this.eventS.subscribe("updateMenu", function () {//登录更新菜单的数据,和加载时间
      that.menuNet();
      that.timeNet();
      that.noticeData();
    }, true);

    this.eventS.subscribe("indexClearTimeOut", function () {//清除计时器
      that.clearAllTimeOut();
    }, true);

    this.eventS.subscribe("indexStartTime", function () {//启动计时器器
      that.timeNet();
      that.getBlanceMoney(); //初始化获取余额
      that.autoPlay();//  启动自动滚动的方法
    }, true);
    //第三方游戏的处理事件
    this.eventS.subscribe("thirdPlayFun", function (type,platform_id,isTest,transVal) {
        if(isTest){ //测试号进入
          if(type=="1"){//表示真人
            that.goEntertainmentUrlNet(platform_id,"1");
          }else if(type=='2'){//表示游戏
            that.goElectronicGameUrlNet(platform_id,that.ng_game_code,"1");
          }else if(type=='3'){//体育竞技
            that.getSportsEventsUrlNet(platform_id,"1");
          }
        }else{
            that.onTrans(platform_id,transVal,type);
        }
    }, true);


  }
  /**
    * 加载菜单
    */
  menuNet() {
    let that = this;
    this.http.get(UrlService.USER_MAIN_HALL, { "callback": "JSONP_CALLBACK" }).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      that.setSessid(data.ssid);
      if (data.code == ConfigService.SUCCESS_CODE) {
        that.lots = []; //热门彩种
        that.lots1 = []; //所有彩种
        that.lots2 = [];  //我的收藏
        let temp = data.data;
        that.store.set(ConfigService.ALL_LOT_STORE_KEY, ToolService.aesDecodeToJson(ToolService.aesDecodeToJson(temp).lots.all));   
        let tt = ToolService.aesDecode(temp);
        that.lotsImg=JSON.parse(tt).banner;
        tt = JSON.parse(tt).lots;
        that.lots=tt.hot;
        that.lots1=tt.all;
        let allLot=tt.all;
        for (let tempData in allLot) {
          that.store.get(ConfigService.IS_LOGIN_STORE_KEY).then((data) => {
            if (!ToolService.isEmpty(data)) {//未登录进行登录
              if (allLot[tempData].is_follow == 1) {
                that.lots2.push(allLot[tempData]);
              }
            }
          });
        }
      } else if (data.code == ConfigService.FAIL_CODE) {
        // this.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        this.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }

  timeNet() {
    let that = this;
    this.http.get(UrlService.USER_TIME, { "callback": "JSONP_CALLBACK" }).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      that.setSessid(data.ssid);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let temp = data.data;
        let tt = ToolService.aesDecodeToJson(temp);
        console.log("所有的时间", tt);
        that.clearAllTimeOut();
        //热门彩种的时间处理
        for (let t1 in that.lots) {
          that.lots[t1]['closeTime'] = "";
          for (let t11 in tt.times) {
            if (that.lots[t1].key == t11) {
              that.lots[t1]['closeTime'] = (tt.times[t11] - tt.now);
            }
          }
        }
        //所有彩种时间处理
        for (let t1 in that.lots1) {
          that.lots1[t1]['closeTime'] = "";
          for (let t11 in tt.times) {
            if (that.lots1[t1].key == t11) {
              that.lots1[t1]['closeTime'] = (tt.times[t11] - tt.now);
            }
          }
        }
        //我的关注的时间处理
        for (let t1 in that.lots2) {
          that.lots2[t1]['closeTime'] = "";
          for (let t11 in tt.times) {
            if (that.lots2[t1].key == t11) {
              that.lots2[t1]['closeTime'] = (tt.times[t11] - tt.now);
            }
          }
        }
        setTimeout(function () {
          that.countdownFun(".hot-lots");
          that.countdownFun(".all-hots");
          that.countdownFun(".collect-lots");
        }, 10);
        that.clearTimer(that.tempRefreshTimeNetArr,true);
        that.tempRefreshTimeNetArr=[];
        let tempRefreshTimeNet = setTimeout(function () {
          that.timeNet();
          clearTimeout(tempRefreshTimeNet);
        }, 10000);
        that.tempRefreshTimeNetArr.push(tempRefreshTimeNet);
      } else if (data.code == ConfigService.FAIL_CODE) {
        // this.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        this.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }
  //
  test() {
    //   let that=this;
    //   this.http.get("http://app.tw8999.com/test/test",{"callback":"JSONP_CALLBACK"}).subscribe(res=>{
    //     let data = res.json();
    //     let temp= data.data;
    //     let tt= ToolService.aesDecode(temp);
    //     this.popWin.toast(tt);
    //     console.log("===========================================");
    //   //  tt=JSON.parse(tt);
    //     console.log(tt);
    //     console.log("===========================================");
    //  },error=>{
    //     console.log("error",error);
    //  });
  }

  
  onStoreFun(lotteryId, is_follow) {
    event.stopPropagation();
    if (is_follow != 1) {//关注的逻辑
      this.storeNet(lotteryId, 1);
    } else {//取消关注
      this.storeNet(lotteryId, 2);
    }
  }

  storeNet(lotteryId, is_follow) {
    let that = this;
    let obj = "{\"lotteryId\":\"" + lotteryId + "\",\"is_follow\":\"" + is_follow + "\"}";
    console.log(obj);
    this.http.get(UrlService.USER_FOLLOW, { "callback": "JSONP_CALLBACK", "data": ToolService.aesEncode(obj) }).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      that.setSessid(data.ssid);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let temp = data.data;
        let tt = ToolService.aesDecode(temp);
        that.menuNet();
        that.timeNet();
        //  console.log(tt);
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }
  /**
   * 首页的公告文件
   */
  noticeData() {
    let that = this;
    this.http.get(UrlService.USER_CONTENT, { "callback": "JSONP_CALLBACK" }).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      that.setSessid(data.ssid);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let temp = data.data;
        that.noticeArr = ToolService.aesDecodeToJson(temp);
        if (ToolService.isEmpty(that.noticeArr+"") || ToolService.isEmpty(that.noticeArr)) {
          that.noticeArr = [];
        }else{
          let t=setTimeout(function(){
            that.marqueeFun();
            clearTimeout(t);
          },200);
        }
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }

  sliderData() {
    let that = this;
    let agentVal = 0;
    if (ConfigService.isAgent == 1) {//代理
      if (ConfigService.is3rd) {//第三方
        agentVal = 3;
      } else {//非第三方
        agentVal = 1;
      }
    } else {//非代理
      if (ConfigService.is3rd) {
        agentVal = 2;
      } else {
        agentVal = 0;
      }
    }
    let obj = "{\"agent\":\"" + agentVal + "\"}";
    this.http.get(UrlService.USER_BANNER, { "callback": "JSONP_CALLBACK", "data": ToolService.aesEncode(obj) }).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      that.setSessid(data.ssid);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let temp = data.data;
        that.imgArr = ToolService.aesDecodeToJson(temp);
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }

  /**
   * 倒计时
   */
  countdownFun(obj: string) {
    let that = this;
    let timeArr = [];
    if (obj == ".hot-lots") {
      this.clearTimer(this.hotTimerArr);
      this.hotTimerArr = [];
    } else if (obj == ".all-hots") {
      this.clearTimer(this.allTimerArr);
      this.allTimerArr = [];
    } else if (obj == ".collect-lots") {
      this.clearTimer(this.collectTimerArr);
      this.collectTimerArr = [];
    }
    $(obj + " .m-t-time").each(function (index) {
      if ($(this).attr("data-value") == "1") {
        let tempObj = $(obj + " .m-t-time").eq(index);
        let temp = parseInt(tempObj.attr("id"));
        let timer = setInterval(function () {
          if (temp <= 0) {
            $(obj + " .m-t-time").eq(index).html("已封盘");
            $(obj + " .m-t-time").eq(index).css("color","#d31111");
            return;
          }
          temp--;
          if (ToolService.isNumber("" + temp)) {
            if ($(obj + " .m-t-time").eq(index).attr("data-code") == 'lhc' || $(obj + " .m-t-time").eq(index).attr("data-code") == 'f3d' || $(obj + " .m-t-time").eq(index).attr("data-code") == 'pl3') {
              tempObj.html(ToolService.formateTime(temp));
            } else {
              tempObj.html(ToolService.formateTime(temp, true));
            }
            $(obj + " .m-t-time").eq(index).css("color","#0070c0");
          }
        }, 1000);
        timeArr.push(timer);
      }
    });
    if (obj == ".hot-lots") {
      this.hotTimerArr = timeArr;
    } else if (obj == ".all-hots") {
      this.allTimerArr = timeArr;
    } else if (obj == ".collect-lots") {
      this.collectTimerArr = timeArr;
    }
  }
  //清除计时器，并清空数据
  clearTimer(timer,isTimeOut?:boolean) {
    if (timer.length > 0) {
      for (let i = 0; i < timer.length; i++) {
        if(isTimeOut){
          clearTimeout(timer[i]);
        }else{
          clearInterval(timer[i]);
        }
        timer[i]=null;
      }
    }
  }

  onSelectMenu(mark) {
    if (this.markIndex != mark) {
      if (mark == 1) {
        this.firstFlag = true; this.secodFlag = false; this.thirdFlag = false;
        if(this.sgList.length<=0){//请求获取双赢彩票的数据
          this.getSGEnterNet();
        }
      } else if (mark == 2) {
        this.firstFlag = false; this.secodFlag = true; this.thirdFlag = false;
      } else if (mark == 3) {
        this.firstFlag = false; this.secodFlag = false; this.thirdFlag = true;
      }
      this.markIndex = mark;
    }
  }

  async toLotdetail(key, name, lotteryId) {
    console.log("key-"+key+"-name-"+name+"-lotteryId-"+lotteryId);
    this.clearAllTimeOut();
    let that = this;
    await this.store.get(ConfigService.IS_LOGIN_STORE_KEY).then((data) => {
      if (ToolService.isEmpty(data)) {//未登录进行登录
        this.navCtrl.navigateForward("/login");
        return;
      } else {
        let param = "{\"code\":\"" + key + "\",\"name\":\"" + name + "\",\"lotteryId\":\"" + lotteryId + "\"}";
        that.router.navigate(['/lotdetail'], {
          queryParams: { "p": ToolService.paramAESEncrypt(param)}
        });
      }
    });
  }

  autoPlay() {
    this.slides.stopAutoplay();
    this.slides.startAutoplay();
  }

  /**
   * 清除首页的倒计时的计时器
   */
  clearAllTimeOut() {
    let that = this;
    that.clearTimer(that.tempRefreshTimeNetArr,true);
    that.tempRefreshTimeNetArr=[];
    that.clearTimer(that.hotTimerArr);
    that.hotTimerArr = [];
    that.clearTimer(that.allTimerArr);
    that.allTimerArr = [];
    that.clearTimer(that.collectTimerArr);
    that.collectTimerArr = [];
  }


  ngAfterViewInit() {
    this.timeNet();
    this.autoPlay();
  }
  ngOnDestroy() {
    this.slides.stopAutoplay();
    this.clearAllTimeOut();
  }
  marqueeFun(){
     if(this.noticeArr.length<=0){
        return;
    }
    let speed=60//速度数值越大速度越慢
			let colee_left2=document.getElementById("n-c-copy");
			let colee_left1=document.getElementById("n-c");
			let widthV=0;
			$("#n-c p").each(function(index){
				let xx=	$("#n-c p").eq(index).width();
				widthV+=xx
			});
      $("#n-c-contain").css("width",2*widthV+"px");
      $("#n-c,#n-c-copy").css("width",widthV+"px");
			let colee_left=document.getElementById("notice-contain");
			colee_left2.innerHTML=colee_left1.innerHTML
			function Marquee3(){
				if(colee_left2.offsetWidth-colee_left.scrollLeft<=0){//offsetWidth 是对象的可见宽度
					colee_left.scrollLeft-=colee_left1.offsetWidth;//scrollWidth 是对象的实际内容的宽，不包边线宽度
				}else{
					colee_left.scrollLeft++;
				}
			}
      let MyMar3=setInterval(Marquee3,speed);  
  }

  setSessid(sessid){
    $("app-root").attr("sessid",sessid);
  }
  /**
   * 关闭那个气泡的界面
   */
  closeContain(){
    $(".download-contain").css("display","none");
  }
  /**
   * 打开下载app的那个单页面
   */
  openDownPage(){
    if(this.isOpen){
      this.isOpen=false;
      this.recommendData();
    }
  }

 async recommendData() {
    let that = this;
    await that.store.get(ConfigService.RECOMMEND).then((data)=>{
        that.isOpen=true;
        if(!ToolService.isEmpty(data)){
          that.toLink(data.mobile.cfg_val);
            return;
        }
    });
    let obj = "{\"type\":\"" + "recommend" + "\"}";
    this.http.get(UrlService.OTHER_CONFIG, { "callback": "JSONP_CALLBACK" , "data": ToolService.aesEncode(obj)}).subscribe(res => {
      that.isOpen=true;
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let temp = data.data;
        let res = ToolService.aesDecodeToJson(temp);
        that.store.set(ConfigService.RECOMMEND,res);
        that.toLink(res.mobile.cfg_val);
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        
      }
    }, error => {
      that.isOpen=true;
      console.log("error", error);
    });
  }

  toLink(url){
    this.iab.create(url, '_system');
  }

  /**
   * 跳转到公告列表的页面去
   */
  toNoticeList(){
     this.clearAllTimeOut();
     this.navCtrl.navigateForward("/notice");
  }

  /**
   * 顶部是否隐藏banner的业务逻辑
   */
  hideSlider(){
    if($(".slide-h-btn.iconfont").hasClass("ion-ios-fanhui1-down")){
      $(".slide-h-btn.iconfont").removeClass("ion-ios-fanhui1-down").addClass("ion-ios-fanhui1-up");
      $(".slide-contain").css("display","none");
      $(".notice-contain").css("margin-top","-10px");
      $("#noticeItem").css("margin-top","-3px");
    }else{
      $(".slide-h-btn.iconfont").removeClass("ion-ios-fanhui1-up").addClass("ion-ios-fanhui1-down");
      $(".slide-contain").css("display","block");
      $(".notice-contain").css("margin-top","-12px");
      $("#noticeItem").css("margin-top","-5px");
    }
  }



  /**
   * 切换第三方的游戏tab
   */
  thirdMenu(index){
      if(index==1 && this.thirdStatus!=index){
          this.getEntertainmentList();
      }else if(index==2 && this.thirdStatus!=index){
          if(this.isEleGame){
            this.getElectronicGameList();
          }else{
            this.getElectronicGameList(2);
          }
      }else if(index==3 && this.thirdStatus!=index){
          if(this.isAGSport){
            if(this.sportList.length<=0){
              this.getSportsEventsList();
          }
          }
          if(this.isSBOSport){
            if(this.sprotBookList.length<=0){
              this.getSportsBookList();
            }
          }
          if(this.isPSSport){
            if(this.psList.length<=0){
              this.getPSList();
            }
          }
      }else if(index==4 && this.thirdStatus!=index){
          if(this.KYData.length<=0){
            this.getKyGetShowList();
          }
          if(this.SWData.length<=0){
            this.getSWGetShowList();
          }
      }
      this.thirdStatus=index;
  }
  /**
   * 开元棋牌游戏列表
   */
  getKyGetShowList(){
    let that = this;
    this.http.get(UrlService.THIRD_KYGAME_GETSHOWLIST, { "callback": "JSONP_CALLBACK"}).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let temp = data.data;
        let res = ToolService.aesDecodeToJson(temp);
        if(!ToolService.isEmpty(res)){
          that.KYData=res;
        }
        console.log("===========开元棋牌游戏列表:",res);
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }
  /**
   * 双赢棋牌
   */
  getSWGetShowList(){
    let that = this;
    this.http.get(UrlService.THIRD_SWGAME_GETSHOWLIST, { "callback": "JSONP_CALLBACK"}).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let temp = data.data;
        let res = ToolService.aesDecodeToJson(temp);
        if(!ToolService.isEmpty(res)){
          that.SWData=res;
        }
        console.log("===========双赢棋牌游戏列表:",res);
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }
/**
 * 跳转到开元链接
 * @param canDemo 是否支持试玩
 * @param kindId 开元棋牌的id
 */
async  goKYGameUrl(canDemo,kindId=0){
      let that=this;
      let isTestPlay=false;
      let isLogin=true;
      await  this.store.get(ConfigService.IS_LOGIN_STORE_KEY).then((data) => {
        if (ToolService.isEmpty(data)) {
          isLogin=false;
          return;
        }
      });
      if(!isLogin){
        this.navCtrl.navigateForward("/login");
        return;
      }
     await  this.store.get(ConfigService.ROLE_KEY).then((data) => {
        if (data == '2') {
          isTestPlay=true;
        }
      });
      that.kindId=kindId;
      if(isTestPlay){//试玩
        that.popWin.toast("暂不支持试玩");
      }else{
        that.eventS.publish("thirdWinShow",that.balance,true,'开元棋牌',that.getMaxPlatformBalance('ky'),'ky',5);
      }
  }
  /**
   * 跳转到开元的真实链接
   */
  goKYGameUrlNet(kindId,money){
    let that = this;
    let obj = "{\"kindId\":\"" + kindId + "\",\"money\":\"" + money + "\"}";
    this.http.get(UrlService.THIRD_KYGAME_GETCHESSGAMESURL, { "callback": "JSONP_CALLBACK", "data": ToolService.aesEncode(obj)}).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let temp = data.data;
        console.log("开元棋牌游戏需要跳转的链接--",temp);
        if(!ToolService.isEmpty(temp)){
          if(that.isNoDevice){
              window.open(temp+"&jumpType=3&backUrl="+window.location.href,"_blank");
          }else{
            let ref= that.iab.create(temp+"&jumpType=3&backUrl=about:blank", '_blank',that.inAppBrowserOption);
            ref.on("loadstop").subscribe(res=>{
                if(res.url=="about:blank"){
                  ref.close();
                }
            });
            ref.on("loaderror").subscribe(res=>{
              ref.close();
            });
          }
        }
        that.getBlanceMoney();
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }
  /**
   * 跳转到双赢棋牌的链接
   */
  async  goSWGameUrl(canDemo,gameId=0){
    let that=this;
    let isTestPlay=false;
    let isLogin=true;
    await  this.store.get(ConfigService.IS_LOGIN_STORE_KEY).then((data) => {
      if (ToolService.isEmpty(data)) {
        isLogin=false;
        return;
      }
    });
    if(!isLogin){
      this.navCtrl.navigateForward("/login");
      return;
    }
   await  this.store.get(ConfigService.ROLE_KEY).then((data) => {
      if (data == '2') {
        isTestPlay=true;
      }
    });
    that.gameId=gameId;
    if(isTestPlay){//试玩
      that.popWin.toast("暂不支持试玩");
    }else{
      that.eventS.publish("thirdWinShow",that.balance,true,'双赢棋牌',that.getMaxPlatformBalance('sw'),'sw',6);
    }
}

goSWGameUrlNet(gameId,money){
  let that = this;
  let home_url="";
  if(that.isNoDevice){
    home_url=window.location.href;
  }else{
    home_url=ConfigService.SERVER_PATH;
  }
  let obj = "{\"game_id\":\"" + gameId + "\",\"money\":\"" + money + "\",\"home_url\":\"" + home_url + "\"}";
  this.http.get(UrlService.THIRD_SWGAME_GETCHESSGAMESURL, { "callback": "JSONP_CALLBACK", "data": ToolService.aesEncode(obj)}).subscribe(res => {
    let data = res.json();
    ToolService.setEncrypt(data.encrypt);
    if (data.code == ConfigService.SUCCESS_CODE) {
      let temp = data.data;
      console.log("双赢棋牌游戏需要跳转的链接--",temp);
      if(!ToolService.isEmpty(temp)){
        if(that.isNoDevice){
            window.open(temp,"_blank");
        }else{
          let ref= that.iab.create(temp, '_blank',that.inAppBrowserOption);
          ref.on("loadstop").subscribe(res=>{
              if(res.url=="about:blank" || res.url.indexOf(ConfigService.SERVER_PATH)>-1){
                ref.close();
              }
          });
          ref.on("loaderror").subscribe(res=>{
            ref.close();
          });
        }
      }
      that.getBlanceMoney();
    } else if (data.code == ConfigService.FAIL_CODE) {
      that.popWin.toast(data.message);
    } else if (data.code == ConfigService.LOGIN_CODE) {
      that.navCtrl.navigateForward("/login");
    }
  }, error => {
    console.log("error", error);
  });
}

  /**
   * 获取真人游戏列表
   */
  getEntertainmentList(){
    let that = this;
    this.http.get(UrlService.THIRD_GETENTERTAINMENTPLAYLIST, { "callback": "JSONP_CALLBACK"}).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let temp = data.data;
        let res = ToolService.aesDecodeToJson(temp);
        if(!ToolService.isEmpty(res)){
          that.entertainment=res;
        }
        console.log("===========第三方的真人游戏列表:",res);
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }
  /**
   * 获取真人的游戏，并跳转链接
   * @param platformId 平台id
   * @param canDemo 是否试玩
   */
 async goEntertainmentUrl(platformId,canDemo,platformName=""){
    let that=this;
    let isTestPlay=false;
    let isLogin=true;
    await  this.store.get(ConfigService.IS_LOGIN_STORE_KEY).then((data) => {
      if (ToolService.isEmpty(data)) {
        isLogin=false;
        return;
      }
    });
    if(!isLogin){
      this.navCtrl.navigateForward("/login");
      return;
    }
   await  this.store.get(ConfigService.ROLE_KEY).then((data) => {
      if (data == '2') {
        isTestPlay=true;
      }
    });
    if(isTestPlay){
        if(canDemo=="1" || canDemo==1){
          //支持试玩且账号是试玩账号
          that.goEntertainmentUrlNet(platformId,1);
          return;
        }else{
          that.popWin.toast("暂不支持试玩");
        }
    }else{
      that.eventS.publish("thirdWinShow",that.balance,true,platformName,that.getMaxPlatformBalance(platformId),platformId,1);
    }
  }



  goEntertainmentUrlNet(platformId,demo){
    let that = this;
    let obj = "{\"platform_id\":\"" + platformId + "\",\"demo\":\"" + demo + "\"}";
    this.http.get(UrlService.THIRD_GETENTERTAINMENTPLAYURL, { "callback": "JSONP_CALLBACK", "data": ToolService.aesEncode(obj)}).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let temp = data.data;
        if(temp=='ag_asia'){
          return;
        }
        console.log("真人游戏需要跳转的链接--",temp);
        if(!ToolService.isEmpty(temp)){
          if(that.isNoDevice){
              window.open(temp,"_blank");
          }else{
            let ref= that.iab.create(temp, '_blank',that.inAppBrowserOption);
            ref.on("loadstop").subscribe(res=>{
                if(res.url=="about:blank"){
                  ref.close();
                }
            });
            ref.on("loaderror").subscribe(res=>{
              ref.close();
            });
          }
        }
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }


  getElectronicGameList(type=1){
    let that = this;
    let obj = "{\"type\":\"" + type + "\"}";
    this.http.get(UrlService.THIRD_GETELECTRONICGAMELIST, { "callback": "JSONP_CALLBACK", "data": ToolService.aesEncode(obj)}).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let temp = data.data;
        let res = ToolService.aesDecodeToJson(temp);
        if(!ToolService.isEmpty(res)){
            that.electronicGame=res.list;
            that.electronicGameSp=res.alone;
        }
        console.log("===========第三方游戏列表:",res);
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }
  /**
   * 
   * @param platform_id 平台的id
   * @param ng_game_code 游戏的code标识
   * @param demo 是否试玩
   */
 async goElectronicGameUrl(platform_id,ng_game_code,canDemo,platformName=""){
    let that=this;
    let isTestPlay=false;
    let isLogin=true;
    await  this.store.get(ConfigService.IS_LOGIN_STORE_KEY).then((data) => {
      if (ToolService.isEmpty(data)) {
        isLogin=false;
        return;
      }
    });
    if(!isLogin){
      this.navCtrl.navigateForward("/login");
      return;
    }
   await  this.store.get(ConfigService.ROLE_KEY).then((data) => {
      if (data == '2') {
        isTestPlay=true;
      }
    });
    this.ng_game_code=ng_game_code;
    if(isTestPlay){
        if(canDemo=="1" || canDemo==1){
          //支持试玩且账号是试玩账号
          that.goElectronicGameUrlNet(platform_id,ng_game_code,1);
          return;
        }else{
          that.popWin.toast("暂不支持试玩");
        }
    }else{
      that.eventS.publish("thirdWinShow",that.balance,true,platformName,that.getMaxPlatformBalance(platform_id),platform_id,2);
    }      
  }

  goElectronicGameUrlNet(platform_id,ng_game_code,demo){
    let that = this;
    let obj = "{\"platform_id\":\"" + platform_id + "\",\"ng_game_code\":\"" + ng_game_code + "\",\"demo\":\"" + demo + "\"}";
  this.http.get(UrlService.THIRD_GETELECTRONICGAMEURL, { "callback": "JSONP_CALLBACK", "data": ToolService.aesEncode(obj)}).subscribe(res => {
    let data = res.json();
    ToolService.setEncrypt(data.encrypt);
    if (data.code == ConfigService.SUCCESS_CODE) {
      let temp = data.data;
      if(temp=='ag_asia'){
          return;
      }
      console.log("游戏需要跳转的链接--",temp);
      if(!ToolService.isEmpty(temp)){
        if(that.isNoDevice){
          window.open(temp,"_blank");
        }else{
          let ref= that.iab.create(temp, '_blank',that.inAppBrowserOption);
          ref.on("loadstop").subscribe(res=>{
            if(res.url=="about:blank"){
              ref.close();
            }
          });
          ref.on("loaderror").subscribe(res=>{
            ref.close();
          });
        }
      }
    } else if (data.code == ConfigService.FAIL_CODE) {
      that.popWin.toast(data.message);
    } else if (data.code == ConfigService.LOGIN_CODE) {
      that.navCtrl.navigateForward("/login");
    }
  }, error => {
    console.log("error", error);
  });
  }

  /**
   * 获取AG体育的列表
   */
  getSportsEventsList(){
    let that = this;
    this.http.get(UrlService.THIRD_GETSPORTSEVENTSLIST, { "callback": "JSONP_CALLBACK"}).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let temp = data.data;
        let res = ToolService.aesDecodeToJson(temp);
        if(!ToolService.isEmpty(res)){
          that.sportList=res;
        }
        console.log("===========第三方体育竞技列表数据:",res);
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }
  /**
   * 跳转到体育竞技
   * @param platform_id 
   * @param canDemo 
   * @param platformName 
   */
  async goSportsEventsUrl(platform_id,canDemo,platformName=""){
    let that=this;
    let isTestPlay=false;
    let isLogin=true;
    await  this.store.get(ConfigService.IS_LOGIN_STORE_KEY).then((data) => {
      if (ToolService.isEmpty(data)) {
        isLogin=false;
        return;
      }
    });
    if(!isLogin){
      this.navCtrl.navigateForward("/login");
      return;
    }
   await  this.store.get(ConfigService.ROLE_KEY).then((data) => {
      if (data == '2') {
        isTestPlay=true;
      }
    });
    if(isTestPlay){
        if(canDemo=="1" || canDemo==1){
          //支持试玩且账号是试玩账号
          that.getSportsEventsUrlNet(platform_id,1);
          return;
        }else{
          that.popWin.toast("暂不支持试玩");
        }
    }else{
      that.eventS.publish("thirdWinShow",that.balance,true,platformName,that.getMaxPlatformBalance(platform_id),platform_id,3);
    } 
  }
  
  /**
   * 获取平博ps的游戏地址
   */
  async  goPSEventsUrl(platformName){
    let that=this;
    let isTestPlay=false;
    let isLogin=true;
    await  this.store.get(ConfigService.IS_LOGIN_STORE_KEY).then((data) => {
      if (ToolService.isEmpty(data)) {
        isLogin=false;
        return;
      }
    });
    if(!isLogin){
      this.navCtrl.navigateForward("/login");
      return;
    }
   await  this.store.get(ConfigService.ROLE_KEY).then((data) => {
      if (data == '2') {
        isTestPlay=true;
      }
    });
    if(isTestPlay){
      that.popWin.toast("暂不支持试玩");
    }else{
      that.eventS.publish("thirdWinShow",that.balance,true,platformName,that.getMaxPlatformBalance("ps"),"ps",7);
    } 
  }

  /**
   * 获取AG体育的数据    
   */
  getSportsEventsUrlNet(platformId,demo){
    let that = this;
    let obj = "{\"platform_id\":\"" + platformId + "\",\"demo\":\"" + demo + "\"}";
    this.http.get(UrlService.THIRD_GETSPORTSEVENTSURL, { "callback": "JSONP_CALLBACK", "data": ToolService.aesEncode(obj)}).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let temp = data.data;
        if(temp=='ag_asia'){
            return;
        }
        console.log("体育竞技需要跳转的链接--",temp);
        if(!ToolService.isEmpty(temp)){
          if(that.isNoDevice){
              window.open(temp,"_blank");
          }else{
            let ref= that.iab.create(temp, '_blank',that.inAppBrowserOption);
            ref.on("loadstop").subscribe(res=>{
               if(res.url=="about:blank"){
                 ref.close();
               }
            });
            ref.on("loaderror").subscribe(res=>{
              ref.close();
            });
          }
        }
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }
 

  ///额度转换的自动处理
  /**
   * 获取余额的数据
   */
 async getBlanceMoney(){
    let isLogin=true;
    let that=this;
    let isTestPlay=false;
    await  this.store.get(ConfigService.IS_LOGIN_STORE_KEY).then((data) => {
        if (ToolService.isEmpty(data)) {
          isLogin=false;
          return;
        }
    });
    if(!isLogin){
        return;
    }
    await  this.store.get(ConfigService.ROLE_KEY).then((data) => {
      if (data == '2') {
        isTestPlay=true;
      }
    });
    if(isTestPlay){//试玩
      return;
    }
    this.http.get(UrlService.THIRD_SHOWTRANS, { "callback": "JSONP_CALLBACK" }).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let res = ToolService.aesDecodeToJson(data.data);
         console.log("获取的余额数据--",res);
         that.balance=res.balance;
         that.listInfo=res.info;
         if(!ToolService.isEmpty(res.error)){   //有其它异常就报出来
          that.popWin.toast(res.error);
         } 
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }
  /**
   * 获取平台的可用余额
   * @param platform_id 平台类型的id值
   */
  getMaxPlatformBalance(platform_id){
    let tempMoney=0;
    for(let item in this.listInfo){
      if(""+platform_id==this.listInfo[item]['platform_id']+""){
        tempMoney=this.listInfo[item]['balance'];
        break;
      }
    }
    return tempMoney;
  }
  /**
   * 进行转换后的真实的玩
   * @param platform_id 平台的id
   */
  onTrans(platform_id,transVal,type){
    let that=this;
    if(!ToolService.isNumber(transVal) || ToolService.isEmpty(transVal) || (transVal=="0")){
      //直接进去玩
      console.log("直接进入");
        if(type=='1'){
          that.goEntertainmentUrlNet(platform_id,"0");
        }else if(type=='2'){
          that.goElectronicGameUrlNet(platform_id,that.ng_game_code,0);
        }else if(type=='3'){ 
          that.getSportsEventsUrlNet(platform_id,"0");
        }else if(type=='4' && platform_id=='sbo'){
          that.goSportBooksUrlNet();
        }else if(type=='5' && platform_id=='ky'){
          that.goKYGameUrlNet(that.kindId,0);
        }else if(type=='6' && platform_id=='sw'){
          that.goSWGameUrlNet(that.gameId,0);
        }else if(type=='7' && platform_id=='ps'){
          that.goPSGameUrlNet();
        }
      return;
    }
    if(parseInt(transVal)>parseInt(this.balance+"")){
      this.popWin.toast("余额不足");
      return;
    }
    if(type=='5' && platform_id=='ky'){//开元棋牌转额度进入游戏，不走额度转化的接口
      that.goKYGameUrlNet(that.kindId,parseInt(transVal));
      return;
    }
    if(type=='6' && platform_id=='sw'){//双赢棋牌转额度进入游戏，不走额度转化的接口
      that.goSWGameUrlNet(that.gameId,parseInt(transVal));
      return;
    }
    let obj = "{\"fromPlatformId\":\"0\",\"toPlatformId\":\"" + platform_id + "\",\"money\":\"" + parseInt(transVal) + "\"}";
    this.http.get(UrlService.THIRD_GAMETRANS, { "callback": "JSONP_CALLBACK", "data": ToolService.aesEncode(obj) }).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let res = ToolService.aesDecodeToJson(data.data);
        //转化成功后去玩
        if(type=='1'){
          that.goEntertainmentUrlNet(platform_id,"0");
        }else if(type=='2'){
          that.goElectronicGameUrlNet(platform_id,that.ng_game_code,0);
        }else if(type=='3'){
          that.getSportsEventsUrlNet(platform_id,"0");
        }else if(type=='4' && platform_id=='sbo'){  //利己SBO的游戏
          that.goSportBooksUrlNet();
        }else if(type=='7' && platform_id=='ps'){  //平博体育ps的游戏
          that.goPSGameUrlNet();
        }
        that.getBlanceMoney();
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast("转帐失败");
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }


  onElecGameType(type){
    if(type==1){
      if(this.isEleGameTwo){
        this.getElectronicGameList();
      }
        this.isEleGame=true;
        this.isEleGameTwo=false;
    }else{
      if(this.isEleGame){
        this.getElectronicGameList(2);
      }
       this.isEleGame=false;
       this.isEleGameTwo=true;
    }
  }

  onChessGameType(type){
    if(type==1){//开元棋牌
      if(this.isChessGameTwo){ 
        this.getChessGameList();
      }
        this.isChessGame=true;  
        this.isChessGameTwo=false;
    }else{//双赢棋牌
      if(this.isChessGame){
        this.getChessGameList(2);
      }
       this.isChessGame=false;
       this.isChessGameTwo=true;
    }
  }

  getChessGameList(type=1){

  }

  onSportType(type){
     if(type==1){//AG体育
        this.isAGSport=true;
        this.isSBOSport=false;
        this.isPSSport=false;
        if(this.sportList.length<=0){
            this.getSportsEventsList();
        }
     }else if(type==2){ //SBO体育
      this.isAGSport=false;
      this.isSBOSport=true;
      this.isPSSport=false;
      if(this.sprotBookList.length<=0){
        this.getSportsBookList();
      }
     }else if(type==3){  //选中平博体育
        this.isAGSport=false;
        this.isSBOSport=false;
        this.isPSSport=true;
        if(this.psList.length<=0){
            this.getPSList();
        }
     }
  }
  /**
   * 获取平博体育的列表数据
   */
  getPSList(){
    let that = this;
    this.http.get(UrlService.THIRD_PS_GETSPORTSBOOKLIST, { "callback": "JSONP_CALLBACK"}).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let temp = data.data;
        let res = ToolService.aesDecodeToJson(temp);
        if(!ToolService.isEmpty(res)){
          that.psList=res;
        }
        console.log("===========第三方体育平博体育列表数据:",res);
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }

  goPSGameUrlNet(){
    let that = this;
    let home_url="";
    if(that.isNoDevice){
      home_url=window.location.href;
    }else{
      home_url=ConfigService.SERVER_PATH;
    }
    this.http.get(UrlService.THIRD_PS_GETSPORTSBOOKURL, { "callback": "JSONP_CALLBACK"}).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let temp = data.data;
        temp+="&externalUrl="+home_url;
        console.log("平博体育ps需要跳转的链接--",temp);
        if(!ToolService.isEmpty(temp)){
          if(that.isNoDevice){
              window.open(temp,"_blank");
          }else{
            let ref= that.iab.create(temp, '_blank',that.inAppBrowserOption);
            ref.on("loadstop").subscribe(res=>{
               if(res.url=="about:blank" || res.url.indexOf(ConfigService.SERVER_PATH)>-1){
                 ref.close();
               }
            });
            ref.on("loaderror").subscribe(res=>{
              ref.close();
            });
          }
        }
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }

  /**
   * 获取利己SBO体育的列表  
   */
  getSportsBookList(){
    let that = this;
    this.http.get(UrlService.THIRD_GETSPORTSBOOKLIST, { "callback": "JSONP_CALLBACK"}).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let temp = data.data;
        let res = ToolService.aesDecodeToJson(temp);
        if(!ToolService.isEmpty(res)){
          that.sprotBookList=res;
        }
        console.log("===========第三方体育竞技SBO列表数据:",res);
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }



  async goSportBooksUrl(canDemo){
    let that=this;
    let isTestPlay=false;
    let isLogin=true;
    await  this.store.get(ConfigService.IS_LOGIN_STORE_KEY).then((data) => {
      if (ToolService.isEmpty(data)) {
        isLogin=false;
        return;
      }
    });
    if(!isLogin){
      this.navCtrl.navigateForward("/login");
      return;
    }
   await  this.store.get(ConfigService.ROLE_KEY).then((data) => {
      if (data == '2') {
        isTestPlay=true;
      }
    });
    if(isTestPlay){//试玩
      that.popWin.toast("暂不支持试玩");
    }else{
     that.eventS.publish("thirdWinShow",that.balance,true,'利己SBO',that.getMaxPlatformBalance('sbo'),'sbo',4);
    }
  }

  goSportBooksUrlNet(){
    let that = this;
    this.http.get(UrlService.THIRD_GETSPORTSBOOKURL, { "callback": "JSONP_CALLBACK"}).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let temp = data.data;
        console.log("体育竞技SBO需要跳转的链接--",temp);
        if(!ToolService.isEmpty(temp)){
          if(that.isNoDevice){
              window.open(temp,"_blank");
          }else{
            let ref= that.iab.create(temp, '_blank',that.inAppBrowserOption);
            ref.on("loadstop").subscribe(res=>{
               if(res.url=="about:blank"){
                 ref.close();
               }
            });
            ref.on("loaderror").subscribe(res=>{
              ref.close();
            });
          }
        }
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }

  getSGEnterNet(){
    let that = this;
    this.http.get(UrlService.THIRD_GETSHOWLIST   , { "callback": "JSONP_CALLBACK"}).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
         console.log(data.data);
         let temp=data.data;
         that.sgBanner=temp.banner.imageUrl;
         that.sgList=temp.list;
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }
  //双赢彩票
  goSYLotter(lotCode=""){
    let that = this;
    let backUrl="";
    if(that.isNoDevice){
      backUrl=window.location.href;
    }else{
      backUrl=ConfigService.SERVER_PATH;
    }
    let obj = "{\"backUrl\":\"" + backUrl + "\",\"lotCode\":\"" + lotCode + "\"}";   
    this.http.get(UrlService.THIRD_GETSGGAMEURL, { "callback": "JSONP_CALLBACK", "data": ToolService.aesEncode(obj)}).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let temp = data.data;
        console.log("双赢彩票需要跳转的链接--",temp);
        if(!ToolService.isEmpty(temp)){
          if(that.isNoDevice){
              window.open(temp,"_blank");
          }else{
            let ref= that.iab.create(temp, '_blank',that.inAppBrowserOption);
            ref.on("loadstop").subscribe(res=>{
               if(res.url=="about:blank" || res.url.indexOf(ConfigService.SERVER_PATH)>-1){
                 ref.close();
               }
            });
            ref.on("loaderror").subscribe(res=>{
              ref.close();
            });
          }
        }
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }

}
